import {fetch} from './fetch'

//取得后台登录地址
export function getSiteConfig() {
    return fetch({
        url: '/api/index/getSiteConfig',
        method: 'post',
        data: {}
    })
}

//获取首页数据
export function getHomeData() {
    return fetch({
        url: '/api/index/getHomeData',
        method: 'post',
        data: {}
    })
}

//获取分类详情
export function getGroupInfo(data) {
    return fetch({
        url: '/api/index/getGroupInfo',
        method: 'post',
        data: {
            group_id: data.group_id
        }
    })
}

//获取分类筛选项信息
export function getGroupScreen(data) {
    return fetch({
        url: '/api/index/getGroupScreen',
        method: 'post',
        data: {
            group_id: data.group_id
        }
    })
}

//取得购物车产品数量
export function getCartNumber() {
    return fetch({
        url: '/api/cart/number',
        method: 'post',
        data: {}
    });
}

//获取分类下的商品列表
export function getGroupGoodsList(data) {
    return fetch({
        url: '/api/index/getGroupGoodsList',
        method: 'post',
        data: {
            group_id: data.group_id,
            screen: data.screen,
            page: data.page,
            limit: data.limit
        }
    })
}

//获取分类下的商品列表
export function getGoodsInfo(data) {
    return fetch({
        url: '/api/index/getGoodsInfo',
        method: 'post',
        data: {
            goods_id: data.goods_id,
        }
    })
}

//获取商品自定义配置项的内容
export function getGoodsTextInfo(data) {
    return fetch({
        url: '/api/index/getGoodsTextInfo',
        method: 'post',
        data: {
            id: data.id,
        }
    })
}

//生成产品资料
export function goodsMake(data) {
    return fetch({
        url: '/api/goods_data/make',
        method: 'post',
        data: {
            goods_id: data.goods_id,
            list: data.list,
            type: data.type
        }
    })
}

//产品规格项目
export function getGoodsSpecInfo(data) {
    return fetch({
        url: '/api/index/getGoodsSpecInfo',
        method: 'post',
        data: {
            goods_id: data.goods_id,
            keyword: data.keyword ?? ""
        }
    })
}

//获取验证码
export function getSendCode(data) {
    return fetch({
        url: '/api/common/sendCode',
        method: 'post',
        data: {
            phone: data.phone,
        }
    })
}

//注册
export function userRegister(data) {
    return fetch({
        url: '/api/common/register',
        method: 'post',
        data: {
            name: data.name,
            phone: data.phone,
            code: data.code,
            company: data.company,
            department: data.department,
            landline: data.landline,
            email: data.email,
            password: data.password,
            again_password: data.again_password
        }
    })
}

//登录
export function userLogin(data) {
    return fetch({
        url: '/api/common/login',
        method: 'post',
        data: {
            phone: data.phone,
            password: data.password,
        }
    })
}

//忘记密码第一步，验证手机号
export function forgetOne(data) {
    return fetch({
        url: '/api/common/forgetOne',
        method: 'post',
        data: {
            phone: data.phone,
        }
    })
}

//忘记密码第二步，验证码获取
export function forgetTwo(data) {
    return fetch({
        url: '/api/common/forgetTwo',
        method: 'post',
        data: {
            phone: data.phone,
            code: data.code
        }
    })
}

//忘记密码第二步，验证码获取
export function forgetThree(data) {
    return fetch({
        url: '/api/common/forgetThree',
        method: 'post',
        data: {
            token: data.token,
            password: data.password,
            again_password: data.again_password
        }
    })
}

//添加到购物车
export function addCart(data) {
    return fetch({
        url: '/api/cart/addCart',
        method: 'post',
        data: {
            model_id: data.model_id,
            num: data.num,
        }
    })
}

//获取购物车列表
export function getCartList() {
    return fetch({
        url: '/api/cart/getCartList',
        method: 'post',
        data: {}
    })
}

//改变购物车数量
export function editCartNum(data) {
    return fetch({
        url: '/api/cart/editCartNum',
        method: 'post',
        data: {
            id: data.id,
            num: data.num
        }
    })
}

//获取购物车列表
export function carDelete(data) {
    return fetch({
        url: '/api/cart/removeCart',
        method: 'post',
        data: {
            id: data.id,
        }
    })
}

//搜索用户
export function searchUser(data) {
    return fetch({
        url: '/api/user/searchUser',
        method: 'post',
        data: {
            phone: data.phone,
        }
    })
}

//提交报价单
export function generateQuotation(data) {
    return fetch({
        url: '/api/quotation/make',
        method: 'post',
        data: {
            ids: data.ids,
            user_id: data.user_id
        }
    })
}

//订单页面，根据购物车ID 获取商品信息
export function getCartGoodsInfo(data) {
    return fetch({
        url: '/api/cart/getCartGoodsInfo',
        method: 'post',
        data: {
            ids: data.ids,
        }
    })
}

//订单页面，根据购物车ID 获取商品信息
export function getInvoiceList(data) {
    return fetch({
        url: '/api/user/getInvoiceList',
        method: 'post',
        data: data
    })
}

//订单页面，根据购物车ID 获取商品信息
export function getAddressList(data) {
    return fetch({
        url: '/api/user/getAddressList',
        method: 'post',
        data: data
    })
}

//添加|修改用户发票信息
export function saveInvoice(data) {
    return fetch({
        url: '/api/user/saveInvoice',
        method: 'post',
        data: {
            id: data.id,
            user_id: data.user_id,
            type: data.type,
            title: data.title,
            code: data.code,
            register_address: data.register_address,
            bank_name: data.bank_name,
            bank_code: data.bank_code,
            register_tel: data.register_tel,
            address: data.address,
            email: data.email
        }
    })
}

//获取省份列表
export function getProvince() {
    return fetch({
        url: '/api/common/getProvince',
        method: 'post',
        data: {}
    })
}

//获取省份列表
export function getCity(data) {
    return fetch({
        url: '/api/common/getCity',
        method: 'post',
        data: {
            pro_id: data.pro_id
        }
    })
}

//添加|修改收货地址
export function saveAddress(data) {
    return fetch({
        url: '/api/user/saveAddress',
        method: 'post',
        data: {
            pro_id: data.pro_id,
            city_id: data.city_id,
            name: data.name,
            address: data.address,
            phone: data.phone,
            landline: data.landline,
            id: data.id,
            user_id: data.user_id,
        }
    })
}

//添加|修改收货地址
export function deleteAddress(data) {
    return fetch({
        url: '/api/user/deleteAddress',
        method: 'post',
        data: {
            id: data.id
        }
    })
}

//创建订单
export function makeOrder(data) {
    return fetch({
        url: '/api/order/makeOrder',
        method: 'post',
        data: {
            address_id: data.address_id,
            invoice_id: data.invoice_id,
            remarks: data.remarks,
            ids: data.ids,
            user_id: data.user_id,
            type: data.type,
        }
    })
}

//获取用户信息
export function getUserInfo() {
    return fetch({
        url: '/api/user/getUserInfo',
        method: 'post',
        data: {}
    })
}

//修改用户头像
export function changeUserImage(data) {
    return fetch({
        url: '/api/user/changeUserImage',
        method: 'post',
        data: {
            image: data.image
        }
    })
}

//保存用户信息
export function changeUserInfo(data) {
    return fetch({
        url: '/api/user/changeField',
        method: 'post',
        data: data
    });
}

//更换绑定的手机号，该接口会返回最新的用户信息
export function replacePhone(data) {
    return fetch({
        url: '/api/user/replacePhone',
        method: 'post',
        data: {
            phone: data.phone,
            code: data.code
        }
    })
}

//更换绑定的手机号，该接口会返回最新的用户信息
export function changePassword(data) {
    return fetch({
        url: '/api/user/changePassword',
        method: 'post',
        data: {
            old_password: data.old_password,
            password: data.password,
            again_password: data.again_password,
        }
    })
}

//更换绑定的手机号，该接口会返回最新的用户信息
export function getIntegralTotal() {
    return fetch({
        url: '/api/user/getIntegralTotal',
        method: 'post',
        data: {}
    })
}

//获取积分列表
export function getIntegralList(data) {
    return fetch({
        url: '/api/user/getIntegralList',
        method: 'post',
        data: {
            page: data.page,
            limit: data.limit
        }
    })
}

//获取积分富文本介绍
export function getIntegralText() {
    return fetch({
        url: '/api/user/getIntegralText',
        method: 'post',
        data: {}
    })
}

//设置默认地址
export function setAddressDefault(data) {
    return fetch({
        url: '/api/user/setAddressDefault',
        method: 'post',
        data: {
            id: data.id
        }
    })
}

//删除用户发票信息
export function deleteInvoice(data) {
    return fetch({
        url: '/api/user/deleteInvoice',
        method: 'post',
        data: {
            id: data.id
        }
    })
}

//获取订单列表
export function getOrderList(data) {
    return fetch({
        url: '/api/order/getOrderList',
        method: 'post',
        data: {
            time: data.time,
            status: data.status,
            order_number: data.order_number,
            page: data.page,
            limit: data.limit,
        }
    })
}

//获取订单详细信息
export function getOrderDetail(data) {
    return fetch({
        url: '/api/order/getOrderDetail',
        method: 'post',
        data: {
            id: data.id,
        }
    })
}

//获取报价单列表
export function getQuotationList(data) {
    return fetch({
        url: '/api/quotation/getQuotationList',
        method: 'post',
        data: {
            page: data.page,
            limit: data.limit,
            time: data.time,
        }
    })
}

//获取报价单列表
export function getQuotationGoods(data) {
    return fetch({
        url: '/api/quotation/getQuotationGoods',
        method: 'post',
        data: {
            id: data.id,
        }
    })
}

//获取报价单列表
export function saveQuotation(data) {
    return fetch({
        url: '/api/quotation/saveQuotation',
        method: 'post',
        data: {
            id: data.id,
            del_goods_arr: data.del_goods_arr,
            goods: data.goods
        }
    })
}

//获取报价单详情
export function getQuotationInfo(data) {
    return fetch({
        url: '/api/quotation/getQuotationInfo',
        method: 'post',
        data: {
            id: data.id
        }
    })
}

//获取报价单详情
export function makeHelpQuotation(data) {
    return fetch({
        url: '/api/quotation/makeHelpQuotation',
        method: 'post',
        data: {
            quotation_id: data.quotation_id,
            user_id: data.user_id
        }
    })
}

//获取报价单详情
export function makePdf(data) {
    return fetch({
        url: '/api/quotation/makePdf',
        method: 'post',
        data: {
            quotation_id: data.quotation_id,
            type: data.type ?? 2
        }
    })
}

//获取分组列表
export function getNewsGroup(data) {
    return fetch({
        url: '/api/index/getNewsGroup',
        method: 'post',
        data: {
            type: data.type,
        }
    })
}

//获取子分组列表
export function getGroupChild(data) {
    let defaults = {
        type: 3,
        limit: 0
    }
    data = Object.assign(defaults, data);
    return fetch({
        url: '/api/index/getGroupChild',
        method: 'post',
        data: data
    })
}

//获取文章详情
export function getNewsInfo(data) {
    return fetch({
        url: '/api/index/getNewsInfo',
        method: 'post',
        data: {
            id: data.id,
        }
    })
}

//获取关于我们的富文本信息
export function getAbout() {
    return fetch({
        url: '/api/index/getAbout',
        method: 'post',
        data: {}
    })
}

//搜索
export function searchGoods(data) {
    return fetch({
        url: '/api/index/searchGoods',
        method: 'post',
        data: {
            name: data.name,
            type: data.type,
            page: data.page,
            limit: data.limit,
        }
    })
}

//搜索文章
export function searchArticle(data) {
    return fetch({
        url: '/api/index/searchArticle',
        method: 'post',
        data: {
            name: data.name,
            type: data.type,
            page: data.page,
            limit: data.limit,
        }
    })
}

//删除报价单
export function quotationDelete(data) {
    return fetch({
        url: '/api/quotation/delete',
        method: 'post',
        data: {
            quotation_id: data.quotation_id,
        }
    })
}

//删除报价单
export function contactus() {
    return fetch({
        url: '/api/index/contactus',
        method: 'post',
        data: {}
    })
}

//报价单产品详情
export function productDetail(data) {
    return fetch({
        url: '/api/product/detail',
        method: 'post',
        data: {
            goods_id: data.goods_id,
            quotation_id: data.quotation_id
        }
    })
}

//向报价单中追加产品
export function quotationAppend(data) {
    return fetch({
        url: '/api/quotation/append',
        method: 'post',
        data: {
            models: data.models,
            quotation_id: data.quotation_id
        }
    })
}

//向报价单中追加产品
export function invite(data) {
    return fetch({
        url: '/api/invite/index',
        method: 'post',
        data: {
            page: data.page,
            limit: data.limit
        }
    })
}

//订单确认收货
export function confirmOrder(data) {
    return fetch({
        url: '/api/order/confirmOrder',
        method: 'post',
        data: {
            id: data.id,
        }
    })
}

//订单对应所有发货单
export function getShipmentList(data) {
    return fetch({
        url: '/api/waybill/index',
        method: 'post',
        data: {
            order_id: data.order_id,
            status: data.status,
            page: 1,
            limit: 9999,
        }
    })
}

//发货单确认收货
export function confirmShipment(data) {
    return fetch({
        url: '/api/waybill/confirm',
        method: 'post',
        data: {
            id: data.id,
        }
    })
}
